<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport"
    content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  <meta name="author" content="火星科技 http://mars3d.cn ">
  <meta name="apple-touch-fullscreen" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no">
  <meta name="x5-fullscreen" content="true">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  <!-- 标题及搜索关键字 -->
  <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  <meta name="description"
    content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS" />

  <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico">
  <title>三维地图 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>


  <!--第三方lib-->
  <script type="text/javascript" src="../lib/include-lib.js" libpath="../lib/"
    include="jquery,jquery.range,font-awesome,bootstrap,bootstrap-checkbox,layer,haoutil,turf,mars3d"></script>

  <link href="css/style.css" rel="stylesheet" />
  <style>
    #toolbar input {
      vertical-align: middle;
      padding-top: 2px;
      padding-bottom: 2px;
    }
  </style>
</head>

<body class="dark">
  <!--加载前进行操作提示，优化用户体验-->
  <div id="mask" class="signmask" onclick="removeMask()"></div>

  <div id="mars3dContainer" class="mars3d-container"></div>

  <!-- 面板 -->

  <div id="toolbar" class="infoview">
    <span style="color: #cad1d1;">提示：单击“添加可视域”后，图上左键绘制两点即可</span>
    <table class="mars-table">
      <tbody>
        <tr title="最大视角水平张角：120度">
          <td>视角水平张角</td>
          <td>
            <input type="range" min="1" max="120" step="1" data-bind="value: horizontalAngle, valueUpdate: 'input'">
          </td>
          <td>
            <input type="number" style="width: 70px" size="5" data-bind="value: horizontalAngle">
          </td>
        </tr>
        <tr title="最大视角垂直张角：90度">
          <td>视角垂直张角</td>
          <td>
            <input type="range" min="1" max="90" step="1" data-bind="value: verticalAngle, valueUpdate: 'input'">
          </td>
          <td>
            <input type="number" style="width: 70px" size="5" data-bind="value: verticalAngle">
          </td>
        </tr>
        <tr title="最远可视距离：5KM">
          <td>视角距离</td>
          <td>
            <input id="viewDis" type="range" min="1" max="5000" step="1"
              data-bind="value: distance, valueUpdate: 'input'">

          </td>
          <td>
            <input id="viewDis1" type="number" style="width: 70px" size="5" data-bind="value: distance">
          </td>
        </tr>
        <tr>
          <td>视椎框线</td>
          <td>
            <div class="checkbox checkbox-info checkbox-inline">
              <input type="checkbox" id="chkDebugFrustum" value="this" name="jiaodu" checked>
              <label for="chkDebugFrustum">显示框线</label>
            </div>
          </td>
          <td>
          </td>
        </tr>
      </tbody>
    </table>
    <br />
    <input id="btnAddPoint" type="button" class="btn btn-primary" value="添加可视域" />
    <input id="btnClear" type="button" class="btn btn-info" value="清除" />
  </div>



  <script src="./js/common.js"></script>
  <script type="text/javascript">
    'use script' //开发环境建议开启严格模式

    var map
    var arrViewField = []

    function initMap(options) {
      //合并属性参数，可覆盖config.json中的对应配置
      var mapOptions = mars3d.Util.merge(options, {
        scene: {
          center: { y: 28.440942, x: 119.482189, z: 191.32, heading: 227.4, pitch: -27.6, roll: 359.9 },
          fxaa: true, //不开启抗锯齿，可视域会闪烁
          globe: {
            depthTestAgainstTerrain: true, //不加无法投射到地形上
          },
        },
      })

      //创建三维地球场景
      map = new mars3d.Map('mars3dContainer', mapOptions)

      //添加参考三维模型
      var tiles3dLayer = new mars3d.layer.TilesetLayer({
        url: 'http://data.marsgis.cn/3dtiles/qx-shequ/tileset.json',
        maximumScreenSpaceError: 2,
        maximumMemoryUsage: 2048,
        dynamicScreenSpaceError: true,
        cullWithChildrenBounds: false,
        luminanceAtZenith: 0.6,
        position: { alt: 3 },
      })
      map.addLayer(tiles3dLayer)

      $('#chkDebugFrustum').change(function () {
        var showFrustum = $(this).is(':checked')

        for (var i = 0, len = arrViewField.length; i < len; i++) {
          arrViewField[i].showFrustum = showFrustum
        }
      })

      //添加可视域
      $('#btnAddPoint').click(function (e) {
        var showFrustum = $('#chkDebugFrustum').is(':checked')

        var thisViewField = new mars3d.thing.ViewShed3D({
          horizontalAngle: Number(viewModel.horizontalAngle),
          verticalAngle: Number(viewModel.verticalAngle),
          distance: Number(viewModel.distance),
          showFrustum: showFrustum,
          offsetHeight: 1.5, //加人的身高等因素，略微抬高一些
        })
        map.addThing(thisViewField)

        thisViewField.on(mars3d.EventType.end, function (event) {
          viewModel.distance = event.distance
        })
        arrViewField.push(thisViewField)
      })

      //清除
      $('#btnClear').click(function (e) {
        for (var i = 0, len = arrViewField.length; i < len; i++) {
          map.removeThing(arrViewField[i], true)
        }
        arrViewField = []
      })

      bindViewModel()
    }

    //面板参数更新
    var viewModel = {
      verticalAngle: 90,
      horizontalAngle: 120,
      distance: 10,
    }

    //绑定面板的参数监听处理
    function bindViewModel() {
      Cesium.knockout.track(viewModel) //面板更新监听

      // Bind the viewModel to the DOM elements of the UI that call for it.
      var toolbar = document.getElementById('toolbar')
      Cesium.knockout.applyBindings(viewModel, toolbar)

      // Make the active imagery layer a subscriber of the viewModel.
      function subscribeLayerParameter(name) {
        Cesium.knockout.getObservable(viewModel, name).subscribe(function (newValue) {
          updateParams()
        })
      }
      subscribeLayerParameter('verticalAngle')
      subscribeLayerParameter('horizontalAngle')
      subscribeLayerParameter('distance')
    }

    function updateParams() {
      if (arrViewField.length === 0) {
        return
      }

      var thisViewField = arrViewField[arrViewField.length - 1]
      if (!thisViewField) {
        return
      }
      thisViewField.distance = Number(viewModel.distance)
      thisViewField.horizontalAngle = Number(viewModel.horizontalAngle)
      thisViewField.verticalAngle = Number(viewModel.verticalAngle)
    }
  </script>
</body>

</html>
